<template>
	<view class="wanl-money">
		<view class="bg-orange padding-bj" style="position: relative;">
			<text class="title">易货积分余额（元）</text>
			<view class="margin-top margin-bottom-xs">
				<text class="text-sl">{{user.money}}</text>
			</view>
			<view class="transfer" @tap="$wanlshop.to('/pages/user/money/transfer')">
				积分互转
			</view>
		</view>
		<!-- 功能 -->
		<view class="cu-list menu sm-border">
			<!-- <view class="cu-item arrow" @tap="$wanlshop.to('/pages/user/money/recharge')">
				<view class="content">
					<text class="wlIcon-chongzhichenggong text-blue"></text>
					<text>充值</text>
				</view>
			</view> -->
			<view class="cu-item arrow" @tap="goWithdraw" v-if="false">
				<view class="content">
					<text class="wlIcon-tixianjilu text-orange"></text>
					<text>提现</text>
				</view>
			</view>
		</view>
		<view class="cu-list menu sm-border">
			<view class="cu-item arrow" @tap="$wanlshop.to('/pages/user/bank/bank')">
				<view class="content">
					<text class="wlIcon-yinhangka text-blue"></text>
					<text>银行卡</text>
				</view>
				<view class="action" >
					<text class="text-sm wanl-gray">用于提现到第三方账户</text>
				</view>
			</view>
			<view class="cu-item arrow" @tap="$wanlshop.to('/pages/user/money/list')">
				<view class="content">
					<text class="wlIcon-yue1 text-orange"></text>
					<text>账单明细</text>
				</view>
			</view>
			<view class="cu-item arrow" @tap="$wanlshop.to('/pages/user/money/witlist')"  v-if="false">
				<view class="content">
					<text class="wlIcon-jinbitixian text-orange"></text>
					<text>提现日志</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {

			};
		},
		computed: {
			...mapState(['user'])
		},
		onShow() {
			this.loadData();
		},
		methods: {
			async loadData() {
				await uni.request({
					url: '/wanlshop/pay/getBalance',
					method: 'POST',
					success: res => {
						this.$store.commit('user/setUserInfo', {
							money: res.data
						});
					}
				});
			},
			async goWithdraw() {
				await uni.request({
					url: '/wanlshop/user/refresh',
					method: 'POST',
					success: res => {
						// console.log(res.data.userinfo, '89999999999999999999999999999999999')
						if (res.data.userinfo.inviter_id) {
							this.$wanlshop.to('/pages/user/money/withdraw')
						} else {
							uni.showModal({
								title: '绑定上级即可提现',
								content: '',
								editable: true, //是否显示输入框
								placeholderText: '请输入上级邀请码', //输入框提示内容
								confirmText: '确认',
								cancelText: '取消',
								success:  async (res) => {
									if (res.confirm) {
										console.log('输入的内容：', res.content);
										if(!res.content) return this.$wanlshop.msg('请输入上级手机号')
										await uni.request({
											url:"/wanlshop/user/inviter_id",
											method:"POST",
											data:{
												mobile:res.content
											},
											success: (res) => {
												this.$wanlshop.to('/pages/user/money/withdraw')
											}
										})
									}
								}
							})
						}
					}
				});
			}
		}
	};
</script>

<style>
	.wanl-money .title {
		color: rgba(255, 255, 255, .7);
	}

	.transfer {
		position: absolute;
		bottom: 24%;
		right: 0;
		width: 180rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border: 1rpx solid #ffffff;
		border-radius: 40rpx 0 0 40rpx;
		border-right: none;
		font-size: 28rpx;
		color: #ffffff;
	}
</style>